package cn.springBoot.controller;


import cn.springBoot.entity.User;
import cn.springBoot.entity.UserActuser;
import cn.springBoot.service.UserActuserService;
import cn.springBoot.service.UserService;
import org.camunda.bpm.engine.IdentityService;
import org.camunda.bpm.engine.impl.persistence.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ljx
 * @since 2021-10-26
 */
@RestController()
@RequestMapping("/userActuser")
public class UserActuserController {


    @Autowired
    private UserService userService;

    //身份验证
    @Autowired
    IdentityService identityService;

    @Autowired
    UserActuserService userActuserService;

    //创建一个用户
    @PostMapping("/createUser")
    public boolean createUser(@RequestBody  User user){



    boolean isOK= userService.insert(user);
    if(isOK){
        UserEntity userEntity = new UserEntity();
        userEntity.setId(user.getUsername());
        userEntity.setFirstName(user.getName());

        userEntity.setEmail(user.getEmail());
        userEntity.setPassword(user.getPassword());
        identityService.saveUser(userEntity);
    }
    UserActuser userActuser=new UserActuser();
    userActuser.setUserId(user.getId());
    userActuser.setActUserId(user.getUsername());
    userActuserService.insert(userActuser);

    return  true;
}



}

